package com.jk.service;

import com.jk.dao.SqjfDao;
import com.jk.entity.ItypeEntity;
import com.jk.entity.SqjfEntity;
import com.jk.entity.UserEntity;
import com.jk.entity.XsjfEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class SqjfService {


    @Autowired
    private SqjfDao dao;


    public List<XsjfEntity> getItemListWithOutContentAndItemTypeList(Integer typeID) {
        return    dao.getItemListWithOutContentAndItemTypeList(typeID);
    }

    public void del(Integer id) {
           dao.del(id);
    }

    public void add(XsjfEntity xsjfEntity,HttpServletRequest request) {
        UserEntity user = (UserEntity) request.getSession().getAttribute("user");
        UserEntity user2=dao.getUserList();

        SqjfEntity sqjfEntity = new SqjfEntity();
        SimpleDateFormat sim1=new SimpleDateFormat("HHmmssSS");
        int floor =(int)Math.round(Math.random() * 899 + 100);
        String id1 = sim1.format(new Date())+""+floor;
        sqjfEntity.setIntegral_number(id1);
        sqjfEntity.setIntegral_state(1);
        sqjfEntity.setIntegral_addup(xsjfEntity.getXsintegral());
        sqjfEntity.setIntegral_conent(xsjfEntity.getXscontent());
        sqjfEntity.setIntegral_title(xsjfEntity.getXstitle());
        sqjfEntity.setIntegral_PribukObjct(user.getName());
        sqjfEntity.setIntegral_auditor(user2.getName());

        dao.add(sqjfEntity);
    }

    public SqjfEntity getById(Integer id) {
        return    dao.getById(id);
    }

    public List<ItypeEntity> getTypeList() {
        return   dao.getTypeList();
    }

    public XsjfEntity getjfId(Integer id, HttpServletRequest request) {
        UserEntity user = (UserEntity) request.getSession().getAttribute("user");
        UserEntity user2=dao.getUserList();
        XsjfEntity xsjfEntity = dao.getjfId(id);
        xsjfEntity.setName(user.getName());
        xsjfEntity.setAdminName(user2.getName());
        return    xsjfEntity;
    }


    public List<SqjfEntity> getaddupList() {
        return dao.getaddupList();
    }

    public List<UserEntity> getUserList1() {
        return   dao.getUserList1();
    }
}
